//
//  main.c
//  C_7数据结构和动态存储
//
//  Created by Robin on 16/3/17.
//  Copyright © 2016年 cnbm. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 递归结构
typedef struct island{
    char *name;
    char *opens;
    char *closes;
    struct island *next;
}island;

void display_island (island *start);// 遍历链表
island* create_island();                // 动态分配内存

int main(int argc, const char * argv[]) {

//    island south_CN = {"海南","7:00","9:00",NULL};// 起点
//    island TaiWan = {"台湾","8:00",":9:00",NULL};
//    island HK = {"香港","6:00","9:00",NULL};
//    island HYD = {"黄岩岛","6:00","10:00",NULL};
//    
//    south_CN.next = &TaiWan;
//    TaiWan.next = &HK;
//    HK.next = &HYD;
//    
//    island KYD = {"库页岛","6:30","17:00",NULL};
//    TaiWan.next = &KYD;
//    KYD.next = &HK;

    island *start = NULL;
    island *i = NULL;
    island *next = NULL;
    
//    for (int j=0; j<10; j++) {
//        printf("j is %i\n",j);
//    }
    
    char name[80];
    for (; fgets(name, 80, stdin) != NULL; i=next) {
        next = create_island(name);
        
        if (start == NULL) {
            start = next;
        }
        
        if (i != NULL) {
            i->next = next;
        }
        
    }
    
    display_island(start);
    
    return 0;
}

island* create_island(char *name){
    
    island *p = malloc(sizeof(island));
    
    p->name = strdup(name);
    p->opens = "7:00";
    p->closes = "19:00";
    p->next = NULL;
    return p;
    
}

void display_island (island *start){
    
    island *i = start;
    
    for (; i != NULL; i = i->next) {
        printf("Name: %s open : %s~%s\n",i->name,i->opens,i->closes);
    }
}
